package com.hb.unic.core.async.impl;

import com.hb.unic.core.async.IMessageChannel;
import com.hb.unic.core.async.IMessageSender;
import org.springframework.stereotype.Component;

import com.hb.unic.core.log.UnicLogger;
import com.hb.unic.core.log.UnicLoggerFactory;

/**
 * 异步消息发送器实现类
 *
 * @since v1.0，2023/8/28 22:26，create by Mr.Huang.
 */
@Component
public class MessageSender implements IMessageSender {

    /**
     * log
     */
    private static final UnicLogger LOGGER = UnicLoggerFactory.getLogger(MessageSender.class);

    @Override
    public void send(AsyncMessage asyncMessage) {
        String messageType = asyncMessage.getMessageType();
        // 获取执行通道
        IMessageChannel channel = MessageConfigManager.getChannel(messageType);
        if (channel == null) {
            LOGGER.warn("Can not get message channel for type: {}", messageType);
            return;
        }
        channel.submit(asyncMessage);
    }

}
